<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="铁塔名称" prop="towerName">
        <el-input
          v-model="queryParams.towerName"
          placeholder="请输入铁塔名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="铁塔编号" prop="towerNum">
        <el-input
          v-model="queryParams.towerNum"
          placeholder="请输入铁塔编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="铁塔类型" prop="towerType">
        <el-input
          v-model="queryParams.towerType"
          placeholder="请输入铁塔类型"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="组织机构" prop="deptId">
        <el-input
          v-model="queryParams.deptId"
          placeholder="请输入组织机构"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="施工单位" prop="consUnit">
        <el-input
          v-model="queryParams.consUnit"
          placeholder="请输入施工单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="铁塔高度" prop="towerHeight">
        <el-input
          v-model="queryParams.towerHeight"
          placeholder="请输入铁塔高度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公里标" prop="milestones">
        <el-input
          v-model="queryParams.milestones"
          placeholder="请输入公里标"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="经度" prop="lon">
        <el-input
          v-model="queryParams.lon"
          placeholder="请输入经度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="纬度" prop="lat">
        <el-input
          v-model="queryParams.lat"
          placeholder="请输入纬度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="上下行位置" prop="upDown">
        <el-input
          v-model="queryParams.upDown"
          placeholder="请输入上下行位置"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="垂直度" prop="vertical">
        <el-input
          v-model="queryParams.vertical"
          placeholder="请输入垂直度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="俯仰角" prop="pitchAngle">
        <el-input
          v-model="queryParams.pitchAngle"
          placeholder="请输入俯仰角"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="方位角" prop="azimuthAngle">
        <el-input
          v-model="queryParams.azimuthAngle"
          placeholder="请输入方位角"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="铁塔与线路中心距离" prop="towerDistance">
        <el-input
          v-model="queryParams.towerDistance"
          placeholder="请输入铁塔与线路中心距离"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:tower:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:tower:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:tower:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:tower:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="towerList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="标识" align="center" prop="towerId" />
      <el-table-column label="铁塔名称" align="center" prop="towerName" />
      <el-table-column label="铁塔编号" align="center" prop="towerNum" />
      <el-table-column label="铁塔类型" align="center" prop="towerType" />
      <el-table-column label="组织机构" align="center" prop="deptId" />
      <el-table-column label="施工单位" align="center" prop="consUnit" />
      <el-table-column label="铁塔高度" align="center" prop="towerHeight" />
      <el-table-column label="公里标" align="center" prop="milestones" />
      <el-table-column label="经度" align="center" prop="lon" />
      <el-table-column label="纬度" align="center" prop="lat" />
      <el-table-column label="上下行位置" align="center" prop="upDown" />
      <el-table-column label="垂直度" align="center" prop="vertical" />
      <el-table-column label="俯仰角" align="center" prop="pitchAngle" />
      <el-table-column label="方位角" align="center" prop="azimuthAngle" />
      <el-table-column label="铁塔与线路中心距离" align="center" prop="towerDistance" />
      <el-table-column label="塔上设备" align="center" prop="towerEquipment" />
      <el-table-column label="状态" align="center" prop="status" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:tower:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:tower:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改铁塔管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="铁塔名称" prop="towerName">
          <el-input v-model="form.towerName" placeholder="请输入铁塔名称" />
        </el-form-item>
        <el-form-item label="铁塔编号" prop="towerNum">
          <el-input v-model="form.towerNum" placeholder="请输入铁塔编号" />
        </el-form-item>
        <el-form-item label="铁塔类型" prop="towerType">
          <el-input v-model="form.towerType" placeholder="请输入铁塔类型" />
        </el-form-item>
        <el-form-item label="组织机构" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入组织机构" />
        </el-form-item>
        <el-form-item label="施工单位" prop="consUnit">
          <el-input v-model="form.consUnit" placeholder="请输入施工单位" />
        </el-form-item>
        <el-form-item label="铁塔高度" prop="towerHeight">
          <el-input v-model="form.towerHeight" placeholder="请输入铁塔高度" />
        </el-form-item>
        <el-form-item label="公里标" prop="milestones">
          <el-input v-model="form.milestones" placeholder="请输入公里标" />
        </el-form-item>
        <el-form-item label="经度" prop="lon">
          <el-input v-model="form.lon" placeholder="请输入经度" />
        </el-form-item>
        <el-form-item label="纬度" prop="lat">
          <el-input v-model="form.lat" placeholder="请输入纬度" />
        </el-form-item>
        <el-form-item label="上下行位置" prop="upDown">
          <el-input v-model="form.upDown" placeholder="请输入上下行位置" />
        </el-form-item>
        <el-form-item label="垂直度" prop="vertical">
          <el-input v-model="form.vertical" placeholder="请输入垂直度" />
        </el-form-item>
        <el-form-item label="俯仰角" prop="pitchAngle">
          <el-input v-model="form.pitchAngle" placeholder="请输入俯仰角" />
        </el-form-item>
        <el-form-item label="方位角" prop="azimuthAngle">
          <el-input v-model="form.azimuthAngle" placeholder="请输入方位角" />
        </el-form-item>
        <el-form-item label="铁塔与线路中心距离" prop="towerDistance">
          <el-input v-model="form.towerDistance" placeholder="请输入铁塔与线路中心距离" />
        </el-form-item>
        <el-form-item label="塔上设备" prop="towerEquipment">
          <el-input v-model="form.towerEquipment" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listTower, getTower, delTower, addTower, updateTower } from "@/api/system/tower";

export default {
  name: "Tower",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 铁塔管理表格数据
      towerList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        towerName: null,
        towerNum: null,
        towerType: null,
        deptId: null,
        consUnit: null,
        towerHeight: null,
        milestones: null,
        lon: null,
        lat: null,
        upDown: null,
        vertical: null,
        pitchAngle: null,
        azimuthAngle: null,
        towerDistance: null,
        towerEquipment: null,
        status: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询铁塔管理列表 */
    getList() {
      this.loading = true;
      listTower(this.queryParams).then(response => {
        this.towerList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        towerId: null,
        towerName: null,
        towerNum: null,
        towerType: null,
        deptId: null,
        consUnit: null,
        towerHeight: null,
        milestones: null,
        lon: null,
        lat: null,
        upDown: null,
        vertical: null,
        pitchAngle: null,
        azimuthAngle: null,
        towerDistance: null,
        towerEquipment: null,
        status: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.towerId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加铁塔管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const towerId = row.towerId || this.ids
      getTower(towerId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改铁塔管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.towerId != null) {
            updateTower(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTower(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const towerIds = row.towerId || this.ids;
      this.$modal.confirm('是否确认删除铁塔管理编号为"' + towerIds + '"的数据项？').then(function() {
        return delTower(towerIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/tower/export', {
        ...this.queryParams
      }, `tower_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
